package com.huilian.iotbox.admin.controller;

import com.huilian.iotbox.admin.service.StatsAgencyService;
import com.huilian.iotbox.admin.service.UserService;
import com.huilian.iotbox.data.common.ServerResponse;
import com.huilian.iotbox.data.controller.BaseController;
import com.huilian.iotbox.data.dto.StatsAgencyDto;
import com.huilian.iotbox.data.vo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author lizhiquan
 * @CreateDate: 2021-04-14 23:31
 * @Description:
 */
@RestController
@RequestMapping("/api/statsAgency")
public class StatsAgencyController extends BaseController {

    @Autowired
    private UserService userService;
    @Autowired
    private StatsAgencyService statsAgencyService;

    @PostMapping("/list")
    public ServerResponse list(HttpServletRequest request, @RequestBody StatsAgencyDto statsAgencyDto) {
        String pageNum =  request.getParameter("pageNum");
        String pageSize =  request.getParameter("pageSize");
        UserInfo userInfo = userService.getLoginUserInfo(request);
        statsAgencyDto.setUserInfo(userInfo);
        statsAgencyDto.setPageNum(Integer.parseInt(pageNum));
        statsAgencyDto.setPageSize(Integer.parseInt(pageSize));
        return ServerResponse.createBySuccess(statsAgencyService.findList(statsAgencyDto));
    }
}
